<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('参赛作品列表')" />
    <style>
        .fixed-table-pagination{
            color: red;
        }
    </style>
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                大赛名称：<select name="gameId" th:with="games=${@gameService.selectGameList(null)}">
                                <option th:each="game : ${games}" th:text="${game.name}" th:value="${game.id}"></option>
                            </select>
                            </li>
                            <li>
                                <label>参赛编号：</label>
                                <input type="text" name="actNo"/>
                            </li>
                            <li>
                                <label>学校：</label>
                                <input type="text" name="school"/>
                            </li>
                            <li>
                                <label>院系：</label>
                                <input type="text" name="faculty"/>
                            </li>
                            <li>
                                <label>作者：</label>
                                <input type="text" name="author"/>
                            </li>
<!--                            <li>-->
<!--                                <label>专业：</label>-->
<!--                                <input type="text" name="major"/>-->
<!--                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:act:add" th:if="${canOperation == true}">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:act:edit" th:if="${canOperation == true}">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:act:remove" th:if="${canOperation == true}">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.importTemplate()" shiro:hasPermission="system:act:view">
                    <i class="fa fa-download"></i> 下载模版
                </a>
                <a class="btn btn-info" onclick="$.table.importExcel('', 500 ,300)" shiro:hasPermission="system:act:import" th:if="${canOperation == true}">
                    <i class="fa fa-upload"></i> 导入
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:act:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:act:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:act:remove')}]];
        var prefix = ctx + "system/act";

        var canOperation = [[${canOperation}]]
        if(editFlag == '' && canOperation == false){
            editFlag = 'hidden'
        }
        if(removeFlag == '' && canOperation == false){
            removeFlag = 'hidden'
        }

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                importTemplateUrl: prefix + "/importTemplate",
                modalName: "参赛作品",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'categoryName',
                    title: '作品类别'
                },
                {
                    field: 'title',
                    title: '命题名称'
                },
                {
                    field: 'actNo',
                    title: '参赛编号'
                },
                {
                    field: 'actName',
                    title: '作品名称'
                },
                {
                    field: 'author',
                    title: '作者'
                },
                {
                    field: 'authorPhone',
                    title: '作者电话'
                },
                {
                    field: 'teacher',
                    title: '指导老师'
                },
                {
                    field: 'teacherPhone',
                    title: '指导老师电话'
                },
                {
                    field: 'school',
                    title: '学校',
                    formatter: function(value, row, index) {
                        var result = value;
                        var beginChar = result.substring(0,1);
                        if("0123456789".indexOf(beginChar) > -1){
                            var begin = result.substring(0,6);
                            begin = begin.replace(/[0-9|-]/ig,"");
                            return begin + result.substring(6);
                        }else{
                            return result;
                        }
                    }
                },
                {
                    field: 'faculty',
                    title: '院系'
                },
                {
                    field: 'major',
                    title: '专业'
                },
                {
                    title: '操作',
                    align: 'center',
                    width: '150',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        // 下载模板
        function importTemplate() {
            var importTemplateUrl = "";
            $.get(importTemplateUrl, function (result) {
                if (result.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
            });
        }
    </script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">

            <div class="form-group">
                <label class="col-sm-3 control-label  is-required">大赛名称：</label>
                <div class="col-sm-8">
                    <select id="gameId" name="gameId" class="form-control  m-b" th:with="games=${games}" required>
                        <option th:each="game : ${games}" th:text="${game.name}" th:value="${game.id}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label  is-required">导入文件：</label>
                <div class="col-sm-8">
                    <input type="file" id="file" name="file"/>
                </div>
            </div>

<!--            <div class="mt10 pt5">-->
<!--                <a onclick="importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>-->
<!--            </div>-->
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>
